home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / CFM-68K SDK / Interfaces / MixedMode.p < prev   
Encoding:
Text File  |  1997-03-17  |  11.8 KB  |  379 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        MixedMode.p
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1.5
  8.  
  9.      Copyright:    © 1984-1997 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. }
  19.  
  20. {$IFC UNDEFINED UsingIncludes}
  21. {$SETC UsingIncludes := 0}
  22. {$ENDC}
  23.  
  24. {$IFC NOT UsingIncludes}
  25.  UNIT MixedMode;
  26.  INTERFACE
  27. {$ENDC}
  28.  
  29. {$IFC UNDEFINED __MIXEDMODE__}
  30. {$SETC __MIXEDMODE__ := 1}
  31.  
  32. {$I+}
  33. {$SETC MixedModeIncludes := UsingIncludes}
  34. {$SETC UsingIncludes := 1}
  35.  
  36.  
  37. {$IFC UNDEFINED __TYPES__}
  38. {$I Types.p}
  39. {$ENDC}
  40. {    ConditionalMacros.p                                            }
  41.  
  42. {$PUSH}
  43. {$ALIGN MAC68K}
  44. {$LibExport+}
  45.  
  46. CONST
  47.     kRoutineDescriptorVersion    = 7;
  48.  
  49. { MixedModeMagic Magic Cookie/Trap number }
  50.     _MixedModeMagic                = $AAFE;
  51.  
  52. {  MixedModeState Version for CFM68K Mixed Mode  }
  53.     kCurrentMixedModeStateRecord = 1;
  54.  
  55. { Calling Conventions }
  56.     
  57. TYPE
  58.     CallingConventionType = INTEGER;
  59.  
  60.  
  61. CONST
  62.     kPascalStackBased            = 0;
  63.     kCStackBased                = 1;
  64.     kRegisterBased                = 2;
  65.     kD0DispatchedPascalStackBased = 8;
  66.     kD1DispatchedPascalStackBased = 12;
  67.     kD0DispatchedCStackBased    = 9;
  68.     kStackDispatchedPascalStackBased = 14;
  69.     kThinkCStackBased            = 5;
  70.  
  71. { ISA Types }
  72.     
  73. TYPE
  74.     ISAType = SInt8;
  75.  
  76.  
  77. CONST
  78.     kM68kISA                    = 0;
  79.     kPowerPCISA                    = 1;
  80.  
  81. { RTA Types }
  82.     
  83. TYPE
  84.     RTAType = SInt8;
  85.  
  86.  
  87. CONST
  88.     kOld68kRTA                    = 0+(0 * (2**(4)));
  89.     kPowerPCRTA                    = 0+(0 * (2**(4)));
  90.     kCFM68kRTA                    = 0+(1 * (2**(4)));
  91.  
  92. {$IFC GENERATINGPOWERPC }
  93.     GetCurrentISA                = kPowerPCISA;
  94.     GetCurrentRTA                = kPowerPCRTA;
  95.  
  96. {$ELSEC}
  97. {$IFC GENERATINGCFM }
  98.     GetCurrentISA                = kM68kISA;
  99.     GetCurrentRTA                = kCFM68kRTA;
  100.  
  101. {$ELSEC}
  102.     GetCurrentISA                = kM68kISA;
  103.     GetCurrentRTA                = kOld68kRTA;
  104.  
  105. {$ENDC}
  106. {$ENDC}
  107.     GetCurrentArchitecture        = 0+(GetCurrentISA + GetCurrentRTA);
  108.  
  109.     kRegisterD0                    = 0;
  110.     kRegisterD1                    = 1;
  111.     kRegisterD2                    = 2;
  112.     kRegisterD3                    = 3;
  113.     kRegisterD4                    = 8;
  114.     kRegisterD5                    = 9;
  115.     kRegisterD6                    = 10;
  116.     kRegisterD7                    = 11;
  117.     kRegisterA0                    = 4;
  118.     kRegisterA1                    = 5;
  119.     kRegisterA2                    = 6;
  120.     kRegisterA3                    = 7;
  121.     kRegisterA4                    = 12;
  122.     kRegisterA5                    = 13;
  123.     kRegisterA6                    = 14;
  124. { A7 is the same as the PowerPC SP }
  125.     kCCRegisterCBit                = 16;
  126.     kCCRegisterVBit                = 17;
  127.     kCCRegisterZBit                = 18;
  128.     kCCRegisterNBit                = 19;
  129.     kCCRegisterXBit                = 20;
  130.  
  131.     
  132. TYPE
  133.     registerSelectorType = INTEGER;
  134.  
  135. { SizeCodes we use everywhere }
  136.  
  137. CONST
  138.     kNoByteCode                    = 0;
  139.     kOneByteCode                = 1;
  140.     kTwoByteCode                = 2;
  141.     kFourByteCode                = 3;
  142.  
  143. { Mixed Mode Routine Records }
  144.     
  145. TYPE
  146.     ProcInfoType = LONGINT;
  147.  
  148. { Routine Flag Bits }
  149.     RoutineFlagsType = INTEGER;
  150.  
  151.  
  152. CONST
  153.     kProcDescriptorIsAbsolute    = $00;
  154.     kProcDescriptorIsRelative    = $01;
  155.  
  156.     kFragmentIsPrepared            = $00;
  157.     kFragmentNeedsPreparing        = $02;
  158.  
  159.     kUseCurrentISA                = $00;
  160.     kUseNativeISA                = $04;
  161.  
  162.     kPassSelector                = $0;
  163.     kDontPassSelector            = $08;
  164.  
  165.     kRoutineIsNotDispatchedDefaultRoutine = $0;
  166.     kRoutineIsDispatchedDefaultRoutine = $10;
  167.  
  168.  
  169. TYPE
  170.     RoutineRecord = RECORD
  171.         procInfo:                ProcInfoType;                            { calling conventions }
  172.         reserved1:                SInt8; (* UInt8 *)                        { Must be 0 }
  173.         ISA:                    ISAType;                                { Instruction Set Architecture }
  174.         routineFlags:            RoutineFlagsType;                        { Flags for each routine }
  175.         procDescriptor:            ProcPtr;                                { Where is the thing we’re calling? }
  176.         reserved2:                UInt32;                                    { Must be 0 }
  177.         selector:                UInt32;                                    { For dispatched routines, the selector }
  178.     END;
  179.  
  180.     RoutineRecordPtr = ^RoutineRecord;
  181.     RoutineRecordHandle = ^RoutineRecordPtr;
  182.  
  183. { Mixed Mode Routine Descriptors }
  184. { Definitions of the Routine Descriptor Flag Bits }
  185.     RDFlagsType = UInt8;
  186.  
  187.  
  188. CONST
  189.     kSelectorsAreNotIndexable    = $00;
  190.     kSelectorsAreIndexable        = $01;
  191.  
  192. { Routine Descriptor Structure }
  193.  
  194. TYPE
  195.     RoutineDescriptor = PACKED RECORD
  196.         goMixedModeTrap:        UInt16;                                    { Our A-Trap }
  197.         version:                SInt8;                                    { Current Routine Descriptor version }
  198.         routineDescriptorFlags:    RDFlagsType;                            { Routine Descriptor Flags }
  199.         reserved1:                UInt32;                                    { Unused, must be zero }
  200.         reserved2:                UInt8;                                    { Unused, must be zero }
  201.         selectorInfo:            UInt8;                                    { If a dispatched routine, calling convention, else 0 }
  202.         routineCount:            UInt16;                                    { Number of routines in this RD }
  203.         routineRecords:            ARRAY [0..0] OF RoutineRecord;            { The individual routines }
  204.     END;
  205.  
  206.     RoutineDescriptorPtr = ^RoutineDescriptor;
  207.     RoutineDescriptorHandle = ^RoutineDescriptorPtr;
  208. {  68K MixedModeStateRecord  }
  209.     MixedModeStateRecordPtr = ^MixedModeStateRecord;
  210.     MixedModeStateRecord = RECORD
  211.         state1:                    UInt32;
  212.         state2:                    UInt32;
  213.         state3:                    UInt32;
  214.         state4:                    UInt32;
  215.     END;
  216.  
  217.  
  218. CONST
  219. { Calling Convention Offsets }
  220.     kCallingConventionWidth        = 4;
  221.     kCallingConventionPhase        = 0;
  222.     kCallingConventionMask        = $F;
  223. { Result Offsets }
  224.     kResultSizeWidth            = 2;
  225.     kResultSizePhase            = kCallingConventionWidth;
  226.     kResultSizeMask                = $30;
  227. { Parameter offsets & widths }
  228.     kStackParameterWidth        = 2;
  229.     kStackParameterPhase        = 0+(kCallingConventionWidth + kResultSizeWidth);
  230.     kStackParameterMask            = $FFFFFFC0;
  231. { Register Result Location offsets & widths }
  232.     kRegisterResultLocationWidth = 5;
  233.     kRegisterResultLocationPhase = 0+(kCallingConventionWidth + kResultSizeWidth);
  234. { Register Parameter offsets & widths }
  235.     kRegisterParameterWidth        = 5;
  236.     kRegisterParameterPhase        = 0+(kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth);
  237.     kRegisterParameterMask        = $7FFFF800;
  238.     kRegisterParameterSizePhase    = 0;
  239.     kRegisterParameterSizeWidth    = 2;
  240.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth;
  241.     kRegisterParameterWhichWidth = 3;
  242. { Dispatched Stack Routine Selector offsets & widths }
  243.     kDispatchedSelectorSizeWidth = 2;
  244.     kDispatchedSelectorSizePhase = 0+(kCallingConventionWidth + kResultSizeWidth);
  245. { Dispatched Stack Routine Parameter offsets }
  246.     kDispatchedParameterPhase    = 0+(kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth);
  247. { Special Case offsets & widths }
  248.     kSpecialCaseSelectorWidth    = 6;
  249.     kSpecialCaseSelectorPhase    = kCallingConventionWidth;
  250.     kSpecialCaseSelectorMask    = $3F0;
  251. { Component Manager Special Case offsets & widths }
  252.     kComponentMgrResultSizeWidth = 2;
  253.     kComponentMgrResultSizePhase = kCallingConventionWidth + kSpecialCaseSelectorWidth; { 4 + 6 = 10 }
  254.     kComponentMgrParameterWidth    = 2;
  255.     kComponentMgrParameterPhase    = kComponentMgrResultSizePhase + kComponentMgrResultSizeWidth; { 10 + 2 = 12 }
  256.  
  257.     kSpecialCase                = $0000000F;
  258.  
  259. { all of the special cases enumerated.  The selector field is 6 bits wide }
  260.     kSpecialCaseHighHook        = 0;
  261.     kSpecialCaseCaretHook        = 0;                            { same as kSpecialCaseHighHook }
  262.     kSpecialCaseEOLHook            = 1;
  263.     kSpecialCaseWidthHook        = 2;
  264.     kSpecialCaseTextWidthHook    = 2;                            { same as kSpecialCaseWidthHook }
  265.     kSpecialCaseNWidthHook        = 3;
  266.     kSpecialCaseDrawHook        = 4;
  267.     kSpecialCaseHitTestHook        = 5;
  268.     kSpecialCaseTEFindWord        = 6;
  269.     kSpecialCaseProtocolHandler    = 7;
  270.     kSpecialCaseSocketListener    = 8;
  271.     kSpecialCaseTERecalc        = 9;
  272.     kSpecialCaseTEDoText        = 10;
  273.     kSpecialCaseGNEFilterProc    = 11;
  274.     kSpecialCaseMBarHook        = 12;
  275.     kSpecialCaseComponentMgr    = 13;
  276.  
  277. {
  278.     NOTES ON USING New[Fat]RoutineDescriptor[Trap] 
  279.     
  280.     When calling these routine from classic 68k code there are two possible intentions.
  281.  
  282.     The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  283.     the code is compiled for CFM the functions create routine descriptors that can be used by
  284.     the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  285.     these functions do nothing so that the code will run on Macintoshes that do not have a
  286.     mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  287.     into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  288.     compile it for any runtime or instruction set architecture, and it will run correctly on the
  289.     intended runtime/instruction platform. All without source changes and/or conditional source.
  290.     
  291.     The other intention is for code that "knows" that it is executing as classic 68k runtime
  292.     and is specifically trying to call code of another architecture using mixed mode. Since the
  293.     routines were designed with classic <-> CFM source compatibility in mind this second case
  294.     is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  295.     it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  296.     are only available to classic 68k callers: rigging the interfaces to allow calling them
  297.     from CFM code will result in runtime failure because no shared library implements or exports
  298.     the functions.
  299.     
  300.  
  301.     This almost appears seamless until you consider "fat" routine descriptors and the advent of
  302.     CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  303.     on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  304.     and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  305.     CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  306.     on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  307.     
  308.     By definition fat routine descriptors are only constructed by code that is aware of the 
  309.     architecture it is executing as and that another architecture exists. Source compatibility
  310.     between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  311.     is not available when building pure classic code.
  312.     
  313.     NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  314.     classic code can use the code fragment manager routine "FindSymbol" to obtain the address of 
  315.     a routine in a shared library and then construct a routine descriptor with both the CFM routine 
  316.     and classic    routine.
  317. }    
  318.  
  319. {$IFC GENERATINGCFM }
  320. FUNCTION NewRoutineDescriptor(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType): UniversalProcPtr;
  321. PROCEDURE DisposeRoutineDescriptor(theProcPtr: UniversalProcPtr);
  322. FUNCTION NewFatRoutineDescriptor(theM68kProc: ProcPtr; thePowerPCProc: ProcPtr; theProcInfo: ProcInfoType): UniversalProcPtr;
  323. {$ELSEC}
  324. FUNCTION NewRoutineDescriptor(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType): UniversalProcPtr;
  325.     {$IFC NOT GENERATINGCFM}
  326.     INLINE $5C4F, $2E9F;
  327.     {$ENDC}
  328. PROCEDURE DisposeRoutineDescriptor(theProcPtr: UniversalProcPtr);
  329.     {$IFC NOT GENERATINGCFM}
  330.     INLINE $584F;
  331.     {$ENDC}
  332. {  Note that the call to NewFatRoutineDescriptor is undefined when GENERATINGCFM is false.  }
  333.  
  334. FUNCTION NewRoutineDescriptorTrap(theProc: ProcPtr; theProcInfo: ProcInfoType; theISA: ISAType): UniversalProcPtr;
  335.     {$IFC NOT GENERATINGCFM}
  336.     INLINE $7000, $AA59;
  337.     {$ENDC}
  338. PROCEDURE DisposeRoutineDescriptorTrap(theProcPtr: UniversalProcPtr);
  339.     {$IFC NOT GENERATINGCFM}
  340.     INLINE $7001, $AA59;
  341.     {$ENDC}
  342. FUNCTION NewFatRoutineDescriptorTrap(theM68kProc: ProcPtr; thePowerPCProc: ProcPtr; theProcInfo: ProcInfoType): UniversalProcPtr;
  343.     {$IFC NOT GENERATINGCFM}
  344.     INLINE $7002, $AA59;
  345.     {$ENDC}
  346. {$ENDC}
  347.  
  348. {$IFC GENERATINGCFM }
  349. {
  350.  CallUniversalProc is only implemented in shared libraries on 68k and PowerPC, it is now
  351.  conditionalize with GENERATINGCFM.  This will catch accidental calls from classic 68K code
  352.  that previously only showed up as linker errors.
  353. }
  354. FUNCTION CallUniversalProc(theProcPtr: UniversalProcPtr; procInfo: ProcInfoType; ...): LONGINT; C;
  355. FUNCTION CallOSTrapUniversalProc(theProcPtr: UniversalProcPtr; procInfo: ProcInfoType; ...): LONGINT; C;
  356. {$ENDC}
  357. {$IFC GENERATING68K }
  358. FUNCTION SaveMixedModeState(VAR stateStorage: MixedModeStateRecord; stateVersion: UInt32): OSErr;
  359.     {$IFC NOT GENERATINGCFM}
  360.     INLINE $7003, $AA59;
  361.     {$ENDC}
  362. FUNCTION RestoreMixedModeState(VAR stateStorage: MixedModeStateRecord; stateVersion: UInt32): OSErr;
  363.     {$IFC NOT GENERATINGCFM}
  364.     INLINE $7004, $AA59;
  365.     {$ENDC}
  366. {$ENDC}
  367.  
  368.  
  369. {$ALIGN RESET}
  370. {$POP}
  371.  
  372. {$SETC UsingIncludes := MixedModeIncludes}
  373.  
  374. {$ENDC} {__MIXEDMODE__}
  375.  
  376. {$IFC NOT UsingIncludes}
  377.  END.
  378. {$ENDC}
  379.